package guij.mail;

import java.util.List;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import com.taobao.api.model.Item;

import guij.dao.mapper.ItemMapper;
import guij.dao.mapper.SubscriberMapper;
import guij.dao.vo.Subscriber;

public class MailSender {
	
	public void run(){
		
		List<Subscriber> subscribers = subscriberMapper.selectSubscribers();
		for(int i =0;i<subscribers.size();i++){
			List<Item> items = itemMapper.selectByNick(subscribers.get(i).getShopNikc());
			Mail mail = MakeMail(items,subscribers.get(i).getMail());
			try {
				mail.sendMail();
			} catch (AddressException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (MessagingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public Mail MakeMail(List<Item> items,String mailto){
		return new Mail();
	}
	
	private ItemMapper itemMapper;
	private SubscriberMapper subscriberMapper;
	public void setItemMapper(ItemMapper itemMapper) {
		this.itemMapper = itemMapper;
	}

	public ItemMapper getItemMapper() {
		return itemMapper;
	}

	public void setSubscriberMapper(SubscriberMapper subscriberMapper) {
		this.subscriberMapper = subscriberMapper;
	}

	public SubscriberMapper getSubscriberMapper() {
		return subscriberMapper;
	}

	
}
